<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>销售激励计算器</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: inline-block;
            width: 150px;
        }
        input[type="text"] {
            width: 200px;
            padding: 5px;
        }
        button {
            padding: 10px 20px;
            background-color: #4CAF50;
            color: white;
            border: none;
            cursor: pointer;
        }
        button:hover {
            background-color: #45a049;
        }
        .result {
            margin-top: 20px;
            font-size: 1.2em;
        }
    </style>
</head>
<body>

<h1>销售激励计算器</h1>

<div class="form-group">
    <label for="actualSales">实际销售额 (A):</label>
    <input type="text" id="actualSales" placeholder="请输入实际销售额">
</div>

<div class="form-group">
    <label for="targetSales">承诺目标 (B):</label>
    <input type="text" id="targetSales" placeholder="请输入承诺目标">
</div>

<div class="form-group">
    <label for="teamActualSales">实际团队销售额 (C):</label>
    <input type="text" id="teamActualSales" placeholder="请输入实际团队销售额">
</div>

<div class="form-group">
    <label for="teamTargetSales">团队目标 (D):</label>
    <input type="text" id="teamTargetSales" placeholder="请输入团队目标">
</div>

<button onclick="calculateIncentives()">计算激励</button>

<div class="result" id="result"></div>

<script>
function calculateIncentives() {
    // 获取输入值
    const actualSales = parseFloat(document.getElementById('actualSales').value);
    const targetSales = parseFloat(document.getElementById('targetSales').value);
    const teamActualSales = parseFloat(document.getElementById('teamActualSales').value);
    const teamTargetSales = parseFloat(document.getElementById('teamTargetSales').value);

    if (isNaN(actualSales) || isNaN(targetSales) || isNaN(teamActualSales) || isNaN(teamTargetSales)) {
        alert("请输入有效的数字！");
        return;
    }

    // 计算个人销售额完成比例 X 和团队目标完成比例 Y
    const X = actualSales / targetSales;
    const Y = teamActualSales / teamTargetSales;

    let personalIncentive = 0;
    let teamIncentive = 0;

    // 计算个人激励金额
    if (X < 0.65) {
        personalIncentive = 0;
    } else if (X >= 0.65 && X < 1) {
        personalIncentive = actualSales * 0.05;
    } else if (X === 1) {
        personalIncentive = actualSales * 0.07;
    } else if (X > 1) {
        personalIncentive = targetSales * 0.07;
    }

    // 计算超出部分
    const delta = Math.max(0, actualSales - targetSales);

    // 计算团队激励系数
    let incentiveCoefficient = 0;
    if (X > 1 && X < 1.25) {
        if (Y < 0.65) {
            incentiveCoefficient = (0.6 + 0) * 0.15;
        } else if (Y >= 0.65 && Y < 1) {
            incentiveCoefficient = (0.6 + 0.3) * 0.15;
        } else { // Y >= 1
            incentiveCoefficient = (0.6 + 0.5) * 0.15;
        }
    } else if (X >= 1.25 && X < 1.5) {
        if (Y < 0.65) {
            incentiveCoefficient = (0.5 + 0) * 0.18;
        } else if (Y >= 0.65 && Y < 1) {
            incentiveCoefficient = (0.5 + 0.3) * 0.18;
        } else { // Y >= 1
            incentiveCoefficient = (0.5 + 0.5) * 0.18;
        }
    } else if (X >= 1.5) {
        if (Y < 0.65) {
            incentiveCoefficient = (0.4 + 0) * 0.2;
        } else if (Y >= 0.65 && Y < 1) {
            incentiveCoefficient = (0.4 + 0.3) * 0.2;
        } else { // Y >= 1
            incentiveCoefficient = (0.4 + 0.5) * 0.2;
        }
    }

    // 计算团队激励金额
    teamIncentive = delta * incentiveCoefficient;

    // 计算总激励金额
    const totalIncentive = personalIncentive + teamIncentive;

    // 显示结果
    document.getElementById('result').innerHTML = `
        <p>个人激励金额: ${personalIncentive.toFixed(2)}</p>
        <p>团队激励金额: ${teamIncentive.toFixed(2)}</p>
        <p>总激励金额: ${totalIncentive.toFixed(2)}</p>
    `;
}
</script>

</body>
</html>